home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / programer2 / euclidlib / h / ewindow < prev    next >
Text File  |  1992-05-02  |  11KB  |  232 lines

  1. /**** ewindow.h ****/
  2. /* Handles windows with euclid pictures in them
  3.  * By Paul Field
  4.  * See !ReadMe file for distribution/modification restrictions
  5.  *
  6.  * N.B. To define the position/size/work area etc of each ewindow, use
  7.  * 'template_syshandle("ewindow")' to get at the window's template and alter
  8.  * it to suit you before you call 'ewindow_create'.
  9.  * Notice that the euclid picture is drawn with its origin at (0,0) so you will
  10.  * probably need negative work area coordinates.
  11.  * I may alter 'ewindow_create' or add some new functions to allow you to define
  12.  * features of ewindows.
  13.  *
  14.  * Things you should be careful of :
  15.  * 1) This module catches palette and mode changes using an 'unknown event processor'
  16.  *    (see win.h). If you use unknown event processors yourself make sure they do not
  17.  *    block palette and mode change messages.
  18.  * 2) Palette changes cause sprites to be redrawn unless they are in raytracing style.
  19.  *    This is likely to change. I will probably add a function that allows you to
  20.  *    choose whether pictures are redrawn on palette changes.
  21.  * 3) This module uses 'alarm.h' to handle multitasking drawing. Under various
  22.  *    circumstances it will remove all alarms with a particular ewindow as a handle.
  23.  *    (I can probably get round this if it is a problem to anyone).
  24.  * 4) This module will also remove processes from a cache's pending queue if they
  25.  *    have a particular ewindow as a handle. (Again, I can probably get round this).
  26.  * 5) Don't change the drawing cache of a structure once it is registered with a window.
  27.  *    (If anyone needs to do this - let me know)
  28.  * 6) If you are using multitasking windows then a structure's drawing cache may
  29.  *    be in use at any time. If you need to use the cache for something
  30.  *    (e.g. drawing into a sprite) then use 'cache_callwhenfree()' to call
  31.  *    your routine. If none of your windows are multitasking or every picture has its
  32.  *    own drawing cache then you do not need to do this.
  33.  * 7) Euclid draws the graphs in inverse in 2 and 4 colour modes on the desktop.
  34.  *    I have arranged the display of sprites so that they do this too.
  35.  *    This means that 256-colour sprites are plotted using colourtrans while
  36.  *    2,4 and 16-colour sprites are plotted useing the desktop colours.
  37.  *    I don't know if this matters to anyone - but I'd thought I'd mention it.
  38.  *
  39.  * Also note :
  40.  * 1) The module should use flex and it is written so that registering 'flex_budge'
  41.  *     with _kernel_register_slotextend() should work.
  42.  *     Unfortunately, Euclid doesn't like it if the flex block
  43.  *     moves between it drawing sections of a multitasking picture.
  44.  *     Tony Cheal (Euclid's author) has told me that it is impractical to move the
  45.  *     cache around during drawing so, for the moment, I have used 'heap_alloc' and
  46.  *     you shouldn't use 'flex_budge'.
  47.  *     I have an idea that may allow the cache and picture (and maybe a sprite
  48.  *     being drawn to) to all be in flex blocks. It may be implemented in a later
  49.  *     version of the module. (If you particularly need the feature contect me
  50.  *     and badger me to put it in).
  51.  *
  52.  * If you use the sprite mode in any windows then you should make its use
  53.  * user-configurable - the user has a fair idea how much memory is needed for other
  54.  * things and so should decide whether to have this memory-hungry feature or not.
  55.  *
  56.  * Using sprites in windows can take up a lot of memory, so I may try using some sort of
  57.  * compression. Decompressing a sprite should still be much faster than asking euclid
  58.  * to redraw the picture.
  59.  *
  60.  * IMPORTANT :
  61.  *   I really need feedback about this module, especially comments on the sprite
  62.  * and multitasking features. I need to know whether function calls for setting up
  63.  * windows are easy or cumbersome to use and if you'd prefer a different way
  64.  * of doing things. For example, instead of including 'closefn' as a parameter
  65.  * in ewindow_create I could add a function 'ewindow_registerclosefn(...)' or
  66.  * perhaps a function 'ewindow_registereventhandler(...)' which passes all window
  67.  * events onto your function.
  68.  * I could also add event handlers for events such as:
  69.  *   update finished
  70.  *   draw called  (could be used to access 'infoblock' or
  71.  *                 to draw in 'extras' over the picture)
  72.  * I also need to know what aspects of windows you need to change
  73.  * (e.g. workarea, picture displayed within, cache).
  74.  * To make this module work I need to know what you are trying to do with it
  75.  * and what problems it gives you.
  76.  */
  77.  
  78. #ifndef __ewindow_h
  79. #define __ewindow_h
  80.  
  81. #include "euclid.h"
  82. #include "wimp.h"
  83.  
  84. typedef struct ewindow_str *ewindow;  /* An opaque type */
  85.  
  86.  
  87. typedef void (*ewindow_closefn) (ewindow, void *);
  88.  
  89. ewindow ewindow_create(const char *title, euclid_drawstyle, euclid_header *structure,
  90.                        const char *camera, ewindow_closefn, void *handle);
  91.  /* Creates a window from the Template 'ewindow' which displays the picture
  92.   * refered to by 'structure' in the style given as seen from 'camera'.
  93.   * (camera may be NULL).
  94.   * If the user clicks on the window's 'close' icon 'ewindow_closefn' will be called
  95.   * (with 'handle' as its second argument) so that you can :
  96.   *   i) Query that the user really wants to close the window
  97.   *  ii) Tidy up any data structures you might have
  98.   * iii) Either close or destroy the window
  99.   *
  100.   * Returns a window structure or NULL if there was not enough memory.
  101.   * You may have multiple windows open.
  102.   * (Window mode defaults to no sprite and no timeout).
  103.   * You should have called 'template_init' and 'flex_init' before you call this.
  104.   * (And for the moment 'heap_init' must be called too - this should not be necessary
  105.   *  in later versions)
  106.   */
  107.  
  108. typedef enum ewindow_spritemode
  109.  { ewindow_smcurrent = -2, ewindow_smdynamic
  110.  }
  111. ewindow_spritemode;
  112.  
  113. void ewindow_usesprite(ewindow ew, BOOL sprite, ewindow_spritemode);
  114.  /* If 'sprite' is TRUE the window will attempt to draw the euclid picture in a sprite
  115.   * and then use this during window redraws (which speeds them up considerably).
  116.   * If there is not enough memory to create a sprite then the window will
  117.   * use euclid to redraw the screen until the memory is available. (It detects
  118.   * this on mode and palette changes).
  119.   * 'ewindow_create' defaults to not using sprites.
  120.   * The sprite mode parameter specifies the mode of the sprite. There are two
  121.   * special values :
  122.   *   ewindow_smcurrent - use the current screen mode as the sprite mode
  123.   *   ewindow_smdynamic - use the current screen mode as the sprite mode and whenever
  124.   *                       the screenmode changes recreate and redraw the sprite in the
  125.   *                       new mode. (Also redraws on palette changes).
  126.   */
  127.  
  128. void ewindow_timing(ewindow ew, char timeout, unsigned int drawgap);
  129.  /* Drawing euclid pictures usually hogs the processor. This call allows picture
  130.   * drawing to occur in several steps (vital if you are going to use the raytracing
  131.   * style). 'timeout' is the number of centiseconds that euclid will spend drawing
  132.   * the picture at one time (roughly).
  133.   *  timeout == 0     - no timeout
  134.   *  timeout == 0xff  - infinite timeout (keep going until mouse event)
  135.   * 'drawgap' is the number of centiseconds between 'spurts' of drawing.
  136.   * 'ewindow_create' defaults to no timeout.
  137.   *
  138.   * Currently multitasking only occurs if a sprite is being used in the window.
  139.   * It is possible (although difficult) to perform a multitasking draw without
  140.   * using sprites and I might try to do this in a later version if I think it is
  141.   * worth the effort.
  142.   */
  143.  
  144. void ewindow_closeoptions(ewindow ew, BOOL freesprite);
  145.  /* If the 'freesprite' is 'TRUE' then whenever the window is closed any sprite
  146.   * memory associated with it will be freed, if it is 'FALSE' the sprite remains
  147.   * intact and any processes (i.e. drawing) continue to work on it.
  148.   *
  149.   * The option set using this call only has an effect when the 'ewindow_close'
  150.   * is called.
  151.   * This call is mainly useful if you are ray-tracing since you may wish to close
  152.   * the window onto the ray-traced picture without losing the picture.
  153.   * 'ewindow_create' defaults to 'freesprite = TRUE'.
  154.   */
  155.  
  156. BOOL ewindow_hassprite(ewindow ew);
  157.  /* Returns TRUE if the window has a sprite associated with it.
  158.   */
  159.  
  160. BOOL ewindow_sprite(ewindow ew, sprite_area ***area, int *offset);
  161.  /* Returns TRUE if the window has a sprite associated with it and returns
  162.   * details of the sprite in 'area' and 'offset'.
  163.   * (Be careful the sprite may not be completely drawn - use 'ewindow_spritecomplete'
  164.   *  to check this)
  165.   * Don't be scared by the triple-indirection, this is necessary because the sprite
  166.   * area is a flex block. You should use the call like this :
  167.   *    { sprite_area **area;
  168.   *      int offset;
  169.   *
  170.   *      if (ewindow_sprite(ew, &area, &offset))
  171.   *       { sprite_id id;
  172.   *
  173.   *         id.tag = sprite_id_addr;
  174.   *         id.s.addr = (char *)(*area) + offset;
  175.   *          || Now you have a direct reference (id.s.addr) don't do anything that
  176.   *          || might move the flex block (see Acorn ANSI C Release 4 manual pp363-4)
  177.   *         sprite_xxxx(*area, &id, ....);
  178.   *       }
  179.   *    }
  180.   * Do not alter the thing that 'area' points to, i.e. don't do anything like
  181.   * '*area = NULL' or attempt to free it, unless you would like your program
  182.   * not to work.
  183.   */
  184.  
  185. BOOL ewindow_updatecomplete(ewindow ew);
  186.  /* Window using sprite :
  187.   *   Returns TRUE if the sprite is completely drawn.
  188.   *   (i.e. will return FALSE if the sprite is not drawn or is part way through
  189.   *   being drawn (multitasking pictures only)).
  190.   * No sprite :
  191.   *   Returns TRUE if the window has no updates pending
  192.   */
  193.  
  194. void ewindow_setstyle(ewindow ew, euclid_drawstyle);
  195.  /* Changes the drawing style of the window. If the style is different from before
  196.   * then the window will be updated.
  197.   */
  198.  
  199. void ewindow_open(ewindow);
  200.  /* Opens the window (at the top of the window stack).
  201.   */
  202.  
  203. void ewindow_update(ewindow);
  204.  /* If the picture changes, call this to redraw the picture.
  205.   * If the window is sharing a drawing cache with multitasking pictures then
  206.   * the update may not occur immediately - you can use 'ewindow_updatecomplete'
  207.   * to check that it has occured.
  208.   * (N.B. Wimp redraws are handled automatically).
  209.   */
  210.  
  211. void ewindow_close(ewindow);
  212.  /* Closes the window.
  213.   * Sprite memory is released if the window is using it.
  214.   */
  215.  
  216. void ewindow_destroy(ewindow);
  217.  /* Closes the window and destroys the window structure
  218.   */
  219.  
  220. wimp_w ewindow_handle(ewindow);
  221.  /* Returns the wimp window handle so that you can do low-level things (such as
  222.   * attaching menus).
  223.   * Be careful what you do with the window, some things may caused undefined behaviour.
  224.   * Especially, don't alter the work area, and use the functions given for things like
  225.   * opening, closing or deleting the window.
  226.   *
  227.   * I am likely to add routines to this module that allow manipulation of the window
  228.   * i.e. changing its work area, position and size. If you want anything in particular
  229.   * included then contact me (contact points are in the !ReadMe file).
  230.   */
  231. #endif
  232.